package com.xmg.day01;

import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TransferQueue;

public class Day01_volatile {
    Thread t1,t2;
    public static volatile boolean flag = true;

    public static void main(String[] args) {

        char[] aI = "123456".toCharArray();
        char[] aC = "ABCDEF".toCharArray();


        TransferQueue<Character> queue = new LinkedTransferQueue<>();
            //this is a change
        new Thread(()->{
            try {
                for (char c : aI) {
                    while(!flag) {
                    }
                    System.out.print(c);
                    flag = false;
                }
            }catch (Exception e){

            }
        }).start();

        new Thread(()->{
            try {
                for (char c : aC) {
                    while(flag){
                    }
                    System.out.print(c);
                    flag=true;
                }
            }catch (Exception e){

            }
        }).start();
    }
}
